home *** CD-ROM | disk | FTP | other *** search
- Path: invincible.astro.uu.se!daniel
- From: daniel@invincible.astro.uu.se (Daniel Kallander)
- Newsgroups: comp.lang.c++
- Subject: Re: Reverting of big array ?
- Date: 29 Mar 1996 18:24:04 GMT
- Organization: Uppsala University
- Distribution: world
- Message-ID: <4jh9s4$238k@columba.udac.uu.se>
- References: <Pine.SOL.3.91.960326132111.6385A-100000@evolution> <3158894A.446B@lmf-di.puc-rio.br>
- NNTP-Posting-Host: invincible.astro.uu.se
-
- In article <3158894A.446B@lmf-di.puc-rio.br>, Paulo Eduardo Neves <neves@lmf-di.puc-rio.br> writes:
- |> Thomas wrote:
- |> >
- |> > I need to revert an array (of chars).
- |> > I used the folowing code:( l=length of array)
- |> >
- |> > char *rev=new char[l+1];
- |> > for(i=l-1,j=0;i>=0;i--,j++) rev[j]=seq[i];
- |> > rev[j]='\0';
- |> >
- |> > this code works, but is terribly slow, when using an string with
- |> > size ~ 6000.
- |> > doing the same with the unix command 'rev' takes 1/2 second.
- |> >
- |> > Any ideas ???
- |> >
- |> > -thomas
- |> >
- |> > Sicheritz Ponten Thomas E. UPPSALA UNIVERSITY
- |>
-
- Don't use chars, use integers of the same bit length as the number
- of bits that your processor uses internally, which should be the
- same as the C 'int' type. Because the byte length of your character
- array probably isn't divisible with the number of bytes in an
- 'int', you have to be careful at the endpoints. In that case,
- it is probably easiest to just revert a few more bytes than
- necessary.
- This should make a substantial difference.
-
- Moreover, you don't really need more than one of your two counters.
- j is a simple function of i, and thus unnecessary.
- --
- -------------------------------------------------------------
- Daniel Kallander, e-mail:daniel@astro.uu.se
- Uppsala Astronomical Observatory
- Theoretical Astrophysics
- SWEDEN
- -------------------------------------------------------------
-